package com.link2room.rodimus.handler.impl;

import com.link2room.common.constant.DefaultValue;
import com.link2room.common.dto.result.base.MemberSessionDto;
import com.link2room.common.dto.threadlocal.ApiThreadLocal;
import com.link2room.common.exception.SysException;
import com.link2room.common.util.L2RAssert;
import com.link2room.rodimus.feign.soundwave.PmsMemberFeignService;
import com.link2room.rodimus.handler.ISignInDrawAwardHandler;
import com.link2room.soundwave.constant.L2RCouponConstant;
import com.link2room.soundwave.dto.param.inside.UsableCouopnsInsideParamDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.link2room.enums.exception.RodimusSysExceptionEnum.SIGN_IN_ERROR;

/**
 * Created by LN on 2018/1/9
 */
@Component("sgnInDrawAwardPMSCouponHandler")
public class SignInDrawAwardPMSCouponHandler implements ISignInDrawAwardHandler {
    @Autowired
    private PmsMemberFeignService pmsMemberFeignService;
    @Override
    public void drawAward(String lhotelGroupCode, String type, String value) throws Exception {
        MemberSessionDto memberSession = ApiThreadLocal.getMemberSessionThreadLocal();
        L2RAssert.isTrue(null == memberSession, new SysException(SIGN_IN_ERROR, "请登录."));
        L2RAssert.isTrue(DefaultValue.F.equals(memberSession.getIsMember()), new SysException(SIGN_IN_ERROR, "请先注册会员."));
        String memberNo = memberSession.getMemberNo();
        UsableCouopnsInsideParamDto paramDto = new UsableCouopnsInsideParamDto();
        paramDto.setL2RMemberNo(memberNo);
        paramDto.setPmsCouponCode(value);
        paramDto.setSaleNum(1);
        paramDto.setSaleType(L2RCouponConstant.SALE_TYPE.SIGNIN);
        pmsMemberFeignService.saleCouponsNew(paramDto);
    }
}
